from mysql.connector import connect
from config.config import convert_to_object

def mysqlSession():
    db_config,block_chain_config  = convert_to_object()
# 建立MySQL連線
    con = connect(
        host=db_config.Host,
        port=db_config.Port,
        user=db_config.Username,
        password=db_config.Pwd,
        database=db_config.DbName,
        charset=db_config.Charset#,
        # parse_dates=db_config.ParseTime
    )
    if con.is_connected():
        print("Connected to MySQL database")
    else :
        print("Fail to connnect MySQL")
        exit(1)

    return con

if __name__ == '__main__':
    mysqlSession()